package edu.tyut.game.dao.circle;

import edu.tyut.game.model.FriendCircle;
import edu.tyut.game.provider.MybatisProvider;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

public interface FriendCircleDao {

    // 增
    @Insert("insert into tb_friend_circle(uid, username, gender, avatar_path, content, images) VALUES (#{uid}, #{username}, #{gender}, #{avatarPath}, #{content}, #{images})")
    void insertFriendCircle(FriendCircle friendCircle);
    // 删
    @Delete("delete from tb_friend_circle where id = #{id}")
    int deleteFriendCircle(int fcId);

    // 改
    @Update("update db_game.tb_friend_circle set username = #{username}, gender = #{gender}, avatar_path = #{avatarPath}, content = #{content}, images = #{images} where id = #{id}")
    int updateFriendCircle(FriendCircle friendCircle);

    // 查
    @SelectProvider(type = MybatisProvider.class, method = "getFriendCirclesOrderByLikes")
    @Results({
            @Result(property = "avatarPath", column = "avatar_path"),
            @Result(property = "likeCounts", column = "like_counts"),
    })
    List<FriendCircle> getFriendCircles(final String order);

    // 点赞 +1
    @Update("update db_game.tb_friend_circle set like_counts = like_counts + 1 where id = #{fcId}")
    int addFriendCircleLike(int fcId);

    // 点赞 -1
    @Update("update db_game.tb_friend_circle set like_counts = like_counts - 1 where id = #{fcId}")
    int subFriendCircleLike(int fcId);
}
